package com.aynu.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;

import java.security.KeyPair;

@Configuration
public class SecurityConfig {
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    @Bean
    public KeyPair keyPair(JWTProperties conf) {
        KeyStoreKeyFactory keyStoreKeyFactory=new KeyStoreKeyFactory(
                conf.getLocation(),
                conf.getPassword().toCharArray()
        );
        return keyStoreKeyFactory.getKeyPair(
                conf.getAlias(),
                conf.getPassword().toCharArray()
        );
    }
}
